import Const from "../Const";
import Actor from "./Actor";

export default class Team{
    id=0
    actors:Actor[]=[]
    getActors():Actor[]{
        return this.actors
    }
    constructor(){
        
    }



    randomActors(){
        for (let i=0;i<6;i++){
            if(Math.random()<0.3){
                this.actors[i]=null
            }else{
                let actor=new Actor()
                actor.order=i
                actor.teamId=this.id
                this.actors[i]=actor
            }
        }
    }



    arrangePos():Map<number,number>{
        let changeMap=new Map()
        for(let i=Const.MAX_ACTOR-1;i>=0;i--){
            if(this.actors[i]){
                let j=i+1
                while(this.isEmptyPos(j)){
                    //交换
                    let actor=this.actors[j-1]
                    this.actors[j-1]=null
                    this.actors[j]=actor
                    changeMap.set(actor.gId,j)
                    j+=1
                    
                }
            }
        }
        return changeMap
    }

    isEmptyPos(pos:number){
        if(pos<0 || pos>=Const.MAX_ACTOR){
            return false
        }
        return !this.actors[pos]
    }

    printInfo(){
        let arr=[]
        for(let i=0;i<this.actors.length;i++){
            let actor=this.actors[i]
            if(!actor){
                arr.push('[   ]')
            }else{
                arr.push(`[${actor.atk},${actor.hp}]`)
            }
        }
        console.log(arr.join(','))
    }

    /**
     * 最前面的
     */
    getFowardActor(){
        for(let i=Const.MAX_ACTOR-1;i>=0;i--){
            let actor=this.actors[i]
            if(actor){
                return actor
            }
        }
        return null
    }

    removeActor(acotr){
        let index=this.actors.indexOf(acotr)
        if(index>=0){
            this.actors.splice(index,1)
        }
    }
    isEmpty(){
        for(let i=0;i<Const.MAX_ACTOR;i++){
            let actor=this.actors[i]
            if(actor){
                return false
            }
        }
        return true
    }
}